//
// inOutMsgCenter.cpp
// ~~~~~~~~~~~~~~
//
// The center to process incoming request and output related replay.

#include "log.h"
#include "inOutMsgCenter.h"

void InOutMsgCenter::startRxMsg(RecvdMsg & inMsg)
{
    inMsgQ->receive(inMsg.msg.data(), Message::HEADER_LEN + Message::MAX_BODY_LEN, inMsg.rxSize, inMsg.priority);
}

void InOutMsgCenter::sendReply(const Message & outReply)
{
    sendReply(outReply.data(), outReply.length(), 0) ;
}

void InOutMsgCenter::sendReply(const void * buffer, std::size_t buffer_size,
                               unsigned int priority)
{
    try
    {
        outMsgQ->send(buffer, buffer_size, priority) ;
    }
    catch (boost::interprocess::interprocess_exception &ex)
    {
        boost::interprocess::message_queue::remove(outMsgQName.c_str());
        LOGCON.infoStream() << ex.what() << "\n";
        return ;
    }

}
